package com.enthusiasm.view;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Rect;
import android.util.Log;
import android.view.MotionEvent;

import com.enthusiasm.constants.AbstractSurfaceView;
import com.enthusiasm.constants.BitmapManager;
import com.enthusiasm.constants.SoundManager;
import com.enthusiasm.engine.MyButton;
import com.enthusiasm.engine.MyRect;
import com.enthusiasm.frame.GameCollectActivity;
import com.enthusiasm.frame.GameMenuActivity;
import com.enthusiasm.frame.GameModeActivity;

public class GameModeView extends AbstractSurfaceView {
	private String tag = "GameModeView";
	
	private Rect screenRect;
	private MyRect backRect;
	private MyRect collectRect;
	private Bitmap bmpBack01;
	private Bitmap bmpBack02;
	private Bitmap bmpCollect01;
	private Bitmap bmpCollect02;
	private Bitmap bmpScreen;
	private MyButton back;
	private MyButton collect;

	public GameModeView(Context context) {
		super(context);
	}

	
	@Override
	public boolean onTouchEvent(MotionEvent event) {
		back.onTouchEvent(event);
		collect.onTouchEvent(event);
		moveTouchEvent(event);
		return true;
	}

	private void moveTouchEvent(MotionEvent event) {
		if(event.getAction() == MotionEvent.ACTION_MOVE){
			
		}
	}


	@Override
	public void draw() {
		canvas.drawBitmap(bmpScreen, null, screenRect, paint);
		back.draw(canvas, paint);
		collect.draw(canvas, paint);
	}

	@Override
	public void logic() {
	}

	@Override
	public void initBitmap() {
		Log.v(tag, "a:initBitmap");
		BitmapManager.getInstance(context).initModeBitmap();
		bmpScreen = BitmapManager.getInstance(context).bmpScreen;
		bmpBack01 = BitmapManager.getInstance(context).bmpBack01;
		bmpBack02 = BitmapManager.getInstance(context).bmpBack02;
		bmpCollect01 = BitmapManager.getInstance(context).bmpCollect01;
		bmpCollect02 = BitmapManager.getInstance(context).bmpCollect02;
		back = new MyButton(bmpBack01,bmpBack02) {
			@Override
			public void doClick() {
				SoundManager.getInstance(context).playSoundClick();
				Intent intent = new Intent(context,GameMenuActivity.class);
				context.startActivity(intent);
				((GameModeActivity)context).finish();
				((GameModeActivity)context).overridePendingTransition(android.R.anim.fade_in,android.R.anim.fade_out);				
			}
		};
		collect = new MyButton(bmpCollect01,bmpCollect02) {
			@Override
			public void doClick() {
				SoundManager.getInstance(context).playSoundClick();
				Intent intent = new Intent();
				intent.setClass(context, GameCollectActivity.class);
				intent.putExtra("index", GameModeActivity.index);
				context.startActivity(intent);
				((GameModeActivity)context).finish();
				((GameModeActivity)context).overridePendingTransition(android.R.anim.fade_in,android.R.anim.fade_out);					
			}
		};
	}

	@Override
	public void initRect() {
		screenRect = new Rect(0, 0, screenW, screenH);
		backRect = new MyRect(screenW/40, screenH/30, screenW/15,screenH/9);
		back.setRect(backRect);
		collectRect = new MyRect(screenW*39/40-screenW/12, screenH/30, screenW/10, screenH/9);
		collect.setRect(collectRect);
	}

	@Override
	public void releaseBitmap() {
		Log.v(tag, "a:relaeasBitmap");
		BitmapManager.getInstance(context).releaseModeBitmap();
	}
}
